//
//  SAPAreaViewController.m
//  CarsHome
//
//  Created by dapeng on 15/12/13.
//  Copyright © 2015年 dapeng. All rights reserved.
//

#import "SAPAreaViewController.h"
#import "SAPCodeViewController.h"
@interface SAPAreaViewController ()<UITableViewDataSource, UITableViewDelegate>
@property (nonatomic, retain) UITableView *tableView;
@property (nonatomic, retain) NSArray     *cnArr;
@end

@implementation SAPAreaViewController
- (void)dealloc {
    [_cnDic release];
    [_cnArr release];
    [_tableView release];
    [super dealloc];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    [self tableViews];
    self.cnArr = [[NSArray alloc] init];
    self.cnArr = [self.cnDic allKeys];
}

-(void)tableViews {
    self.tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"UITableViewCellIndentifier"];
    [self.view addSubview:self.tableView];
    [_tableView release];
}

#pragma mark - UITableViewDelegate
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"UITableViewCellIndentifier"];
    cell.textLabel.text = self.cnArr[indexPath.row];
    
    return cell;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.cnArr.count;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:NO];
    SAPCodeViewController *codeVC = [[SAPCodeViewController alloc] init];
    NSDictionary *dic = self.cnDic.allValues[indexPath.row];
    codeVC.areaDic = dic;
    [self.navigationController pushViewController:codeVC animated:YES];
  
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}
@end
